/*! =======================================================
                      VERSION  1.1.0
 * ========================================================
 * webpack.dev.config.js
 * ========================================================
 * 本文件为生产发布配置文件
 * 通过 $npm run dev 命令进行开发调试
 * ======================================================== */
'use strict';

let path              = require('path'),
    webpack           = require('webpack'),
    webpackConfig     = require("./webpack.base.config"),
    WebpackDevServer  = require("webpack-dev-server"),
    HtmlWebpackPlugin = require("html-webpack-plugin"),
    _                 = require("lodash"),
    ip                = require('ip');

let ip_address = 'localhost';//ip.address();
let port = 8080;

webpackConfig.plugins.push(
  // 启动模块热替换
  // new webpack.HotModuleReplacementPlugin(),
  // html文件注入
  new HtmlWebpackPlugin({
    template: path.join(__dirname,'/src/index.html'),
    inject: true
  }),
  //dev dll require包
  new webpack.DllReferencePlugin({
    context: path.join(__dirname, ".", "dll"),
    manifest: require('./dll/vendor.json')
  })
);

webpackConfig.plugins.some(function(plugin, i){
 if(plugin instanceof webpack.optimize.CommonsChunkPlugin) {
   webpackConfig.plugins.splice(i, 1);

   return true;
 }
});

let devConfig = _.merge(webpackConfig,
{
  name: 'client',
  target: 'web',
  entry: {
      // app入口配置
      app:
      [
          `webpack-dev-server/client?http://${ip_address}:${port}`,
          'webpack/hot/dev-server',
           path.join(__dirname, '/src/app.dev.js')
      ]
  },
  output:{
      publicPath:`http://${ip_address}:${port}/`,
  }
});

webpack(devConfig);

module.exports= devConfig;
